def find_circle(node):
    def get_point():
        fast, slow = node, node
        while True:
            slow = slow.next
            fast = fast.next.next if fast.next else None
            if slow == fast:
                return slow
            elif fast is None:
                return fast

    def get_length(point):
        stay, move = point, point
        steps = 0
        while True:
            move = move.next
            steps += 1
            if stay == move:
                return steps

    def get_ans(length):
        behind, ahead = node, node
        for i in range(length):
            ahead = ahead.next
        while behind != ahead:
            behind = behind.next
            ahead = ahead.next
        return behind

    point = get_point()
    if not point:
        return None
    length = get_length(point)
    ans = get_ans(length)
    return ans.val


from utils import circle12345, list1, circle1
print(find_circle(circle12345))
print(find_circle(list1))
print(find_circle(circle1))
